package com.kuwei.servlet;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.kuwei.base.ParamerException;
import com.kuwei.base.ServiceException;
import com.kuwei.servlet.frame.BaseServlet;
import com.kuwei.utils.CommonUtils;
import com.kuwei.utils.Constants;
import com.kuwei.utils.ReturnResult;
import com.kuwei.utils.ServiceConstants;
import com.kuwei.utils.Utility;

@Service("codeConfigServlet")
public class CodeConfigServlet extends BaseServlet{

	
	public void getCodeConfig(HttpServletRequest request,HttpServletResponse response,Map<String, Object> rtnMap) throws ServiceException, ParamerException{
		ReturnResult result = new ReturnResult();
		Map<String, Object> param = Utility.Params.parseParams(request);
		Map<String,Object> reqMap = new HashMap<String, Object>();
		reqMap.put("STATUS_CD", Constants.STATE_1000);
		if(!CommonUtils.isEmpty(param.get("codeType"))){
			String codeType = (String) param.get("codeType");
			String tableName = null;
			String table_column = null;
			if("prodStatus".equals(codeType)){
				tableName = "product";
				table_column = "status_cd";
			} else if("procStatus".equals(codeType)){
				tableName = "procedure_num";
				table_column = "status_cd";
			} else if("userStatus".equals(codeType)){
				tableName = "sys_user";
				table_column = "status_cd";
			}else if("userType".equals(codeType)){
				tableName = "sys_user";
				table_column = "type";
			}else{
				result.setContent(Constants.FAIL, "");
				return;
			}
			
			try {
				reqMap.put("TABLE_NAME", tableName);
				reqMap.put("TABLE_COLUMN", table_column);
				List<Map<String, Object>> list = sqlSessionDaoSupport.getSqlSession().selectList(ServiceConstants.QUERY_CODE_CONFIG,reqMap);
				result.setContent(Constants.SUCCESS, null,list);
			} catch (Exception e){
				result.setContent(Constants.FAIL, e.getMessage());
			}
		} else{
			throw new ParamerException("Parameter[codeType] is empty, please check it!");
		}
		
		rtnMap.put("data", result.getContent());
	}
}
